package com.material.demo.views;

import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

/**
 * Created by pc on 2016/12/12.
 */

public class ScaleBehaior extends CoordinatorLayout.Behavior {

    private final float a = .3f;
    private int width;
    private int height;
    private static final String TAG = ScaleBehaior.class.getName();

    public ScaleBehaior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        return dependency instanceof AppBarLayout;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        float scaleY = Math.abs(dependency.getY()) / dependency.getHeight();
        float scaleX=  Math.abs(dependency.getX()) / dependency.getHeight();

        float y =  (1-scaleY);
        float x = (1-scaleX);

        child.setScaleY(y);
        child.setScaleX(y);

        logMsg("Parent : " + parent.getY() +"   "+ parent.getHeight() +"   "+ x +"   "+ y +"   "+scaleY );
        return true;
    }

    private void logMsg(String msg){
        Log
                .e(TAG,msg);
    }

}
